Skip to content

feat(extract): model unions, unit structs and COM interfaces as containers - #213

Merged
sunerpy merged 1 commit into
mainfrom
feat/tier3-union-nodes
Aug 20, 2026
Merged

sunerpy merged 1 commit into
mainfrom
feat/tier3-union-nodes

Conversation

@sunerpy

@sunerpy sunerpy commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Tier 3 of the post-v1.5.0 upstream sync. Three declarations a reader treats as types were invisible or mis-shaped, so the graph disagreed with the source.

Item 9 — union becomes a kind (upstream PR #1516)

A bare union U { ... } produced no node, and typedef union { ... } A; was recorded as a type_alias. Worse, a C++ union's member method had no container to belong to, so it degraded into a free function — and callers were absorbed by a same-named struct method:

union WithMethod  { int i; int read_field() { return i; } };
struct SOther     { int s; int read_field() { return s; } };
int useUnion(WithMethod w) { return w.read_field(); }

before:  function | read_field @L1        ← orphaned
         useUnion -> read_field@L2        ← bound to SOther, the WRONG type
after:   union:WithMethod contains method:read_field

That is a false edge, not a gap. union now covers C, C++, ObjC (union_specifier) and Rust (union_item). TypeScript's A | B stays a type alias, as upstream has it. No new EdgeKind — upstream adds none.

The variant is appended to NodeKind, which keeps every other discriminant and therefore every existing node id stable.

Item 7 — Rust unit structs (#1513)

struct Unit; was dropped before its node was minted, taking its impl Trait for Unit edge with it — so the loss concentrated in exactly the marker and test-double layers. Bodiless structs are now definitions where the language says so, opt-in per language rather than globally.

Function-local structs remain unindexed, verified as independent of whether they have a body:

struct TopUnit;                    → indexed (this fix)
struct TopBody { x: u32 }          → indexed
fn f() { struct LocalUnit; … }     → NOT indexed, unchanged and deliberate

Item 8 — the MSVC COM interface keyword (#1519)

It parsed as a function, losing three things at once: the container, its members' method kind, and its base-class reference. It is now rewritten to struct before parsing — but behind a lexical mask, because a naive keyword match corrupts real code:

shape naive rule why it matters
block comment rewrites inside it a complete declaration in a comment becomes the next node's docstring — verified
interface class IFoo → struct class IFoo invalid C++; breaks a file that parses today
raw string, #define continuation rewrites neutralised by tree-sitter, but that is a grammar detail we do not own

So comments, character/string/raw-string literals and whole preprocessor logical lines are excluded, as is interface class. The negatives are pinned by extraction-invariance against measured values — the sharpest being INegCli.docstring == "interface INegComment;" — not by "the substitution did not fire".

Golden movement, enumerated

EXTRACTION_VERSION 6 → 7, once. The cpp corpus is regenerated for seven new fixtures (10 → 17 files) and a rust corpus is added; the other fourteen are byte-identical.

Every pre-existing row is compared across all four artifacts — nodes/files for exact equality, refs and edges as multisets, with a new edge permitted only when its source node lives in a new fixture file. That width is not decorative: get was already defined twice in the cpp corpus, so a third same-named member could have re-pointed an existing edge invisibly. The new member is named read_field for the same reason.

Whole-repo self-index — the regression check that matters

baseline after
struct 386 439 +53 bodiless declarations now indexed
implements 22 75 +53, pairing exactly with the new structs
union 0 0 this repo has no Rust union — must not move
function / method / type_alias 5908 / 2182 / 22 unchanged
extends 8 8
refs 34593 34593

0 edges removed, 931 added, and not one calls edge changed — 53 new nodes entered the graph without re-pointing any candidate set. That is precisely the class of regression Tier 2 shipped and caught only by this diff, which is why it is a gate here.

The predicted struct count was 443; the real number is 439, and the difference is explained rather than absorbed: of 57 grep matches, 2 live inside Rust raw-string test data and 2 are function-local, leaving 53 eligible and 53 indexed.

Verification

  • make ci green: 129 suites / 3231 passed / 0 failed (baseline 128 / 3214).
  • Hands-on QA on a real index for all three items.
  • reference/golden/erlang/edges.json still holds its 2 legitimate recursive calls self-edges.
  • Two plan claims did not reproduce and were closed by measurement rather than restated: the class|struct exclusion's RED lives in the 15-shape unit test rather than the combined-file test, and the re-pointed C++ calls edge turns out to be fixed at extraction, not in matchMethodCall. A test written for the latter passed with the change reverted and was deleted rather than shipped.

…iners

Three declarations that a reader treats as types were invisible or mis-shaped,
so the graph disagreed with the source.

A union was not a kind at all. A bare `union U { ... }` produced no node, while
`typedef union { ... } A;` was recorded as a type alias — and a C++ union's
member method, having no container to belong to, degraded into a free function
whose callers were then absorbed by a same-named struct method. That last part
is a false edge, not a gap: a call on the union bound to the wrong type
entirely. `union` is now a first-class kind for C, C++, ObjC and Rust, appended
to NodeKind so every other variant's discriminant — and therefore every
existing node id — stays put. TypeScript's `A | B` remains a type alias, as
upstream has it.

A Rust unit struct was dropped before its node was minted, taking its
`impl Trait for Unit` edge with it, which concentrated the loss in exactly the
marker and test-double layers. Bodiless structs are now definitions where the
language says they are, opt-in per language rather than globally. Function-local
structs stay unindexed, unchanged and deliberate.

The MSVC COM `interface` keyword parsed as a function, losing the container, its
members' method kind, and its base-class reference. It is now rewritten to
`struct` before parsing, behind a lexical mask: comments, character, string and
raw-string literals, and whole preprocessor logical lines are excluded, as is
`interface class`. A naive keyword match corrupts real code — it rewrites inside
a block comment, where a complete declaration becomes the next node's
docstring, and it turns C++/CLI `interface class` into invalid syntax.

EXTRACTION_VERSION 6 -> 7. The cpp golden is regenerated for seven new fixtures
and a rust corpus is added; the other fourteen are byte-identical, with every
pre-existing row compared across nodes, edges, refs and files. On this repo the
change adds 53 struct nodes and their 53 implements edges and removes nothing.
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.94118% with 36 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-extract/src/lang/cpp.rs 89.09% 29 Missing ⚠️
crates/codegraph-extract/src/walker.rs 97.01% 6 Missing ⚠️
crates/codegraph-extract/src/lang/objc.rs 83.33% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (92.94%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
- Coverage   95.27%   95.25%   -0.02%     
==========================================
  Files         137      137              
  Lines       74430    74928     +498     
==========================================
+ Hits        70912    71374     +462     
- Misses       3518     3554      +36     
Files with missing lines Coverage Δ
crates/codegraph-core/src/types.rs 100.00% <100.00%> (ø)
crates/codegraph-extract/src/lang/c.rs 95.55% <100.00%> (+0.10%) ⬆️
crates/codegraph-extract/src/lang/rust.rs 96.74% <100.00%> (+0.08%) ⬆️
crates/codegraph-extract/src/spec.rs 87.23% <100.00%> (+0.87%) ⬆️
crates/codegraph-graph/src/graph/mod.rs 95.35% <ø> (ø)
crates/codegraph-graph/src/query/scoring.rs 98.56% <100.00%> (+<0.01%) ⬆️
crates/codegraph-mcp/src/engine.rs 97.56% <ø> (ø)
crates/codegraph-resolve/src/context.rs 98.14% <ø> (ø)
crates/codegraph-resolve/src/import_resolver.rs 96.40% <ø> (ø)
crates/codegraph-resolve/src/name_matcher.rs 97.47% <100.00%> (+0.01%) ⬆️
... and 8 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit 0b365ed into main Aug 20, 2026
7 checks passed
@sunerpy
sunerpy deleted the feat/tier3-union-nodes branch August 20, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant